from pyomo.environ import *

model = ConcreteModel()

#定义决策变量
model.x = Var(domain=Reals)
model.y = Var(domain=Reals)

#定义目标函数
model.z = Objective(expr = model.x -2*model.y,sense=minimize)

#定义约束条件
model.subject1 = Constraint(expr = 2*model.x+model.y-2>=0)
model.subject2 = Constraint(expr = model.x-2*model.y+4>=0)
model.subject3 = Constraint(expr = 3*model.x-model.y-3<=0)

#打印模型的相关信息
model.pprint()

#求解最优解
opt = SolverFactory('glpk', executable='C:\\software\\winglpk-4.65\\glpk-4.65\\w64\\glpsol')
opt.solve(model)

print("\noptimal solution:\n")
print("x={}\n".format(model.x()))
print("y={}\n".format(model.y()))
print("z={}\n".format(model.z()))